set more off

use dataset, clear

gen othervoteshare = nadervotes/totalvotes*100 if year == 2000
replace othervoteshare = perotvotes/totalvotes*100 if year == 1992

gen f4override = f4.override

eststo clear

eststo: reg othervoteshare f4override if year == 1992 [aw=totalvotes]
eststo: reg othervoteshare f4overridep if year == 1992 [aw=totalvotes]
eststo: reg othervoteshare f4overridel if year == 1992 [aw=totalvotes]

eststo: reg othervoteshare f4override if year == 2000 [aw=totalvotes]
eststo: reg othervoteshare f4overridep if year == 2000 [aw=totalvotes]
eststo: reg othervoteshare f4overridel if year == 2000 [aw=totalvotes]

label variable f4override "Held increase vote, t+4"
label variable f4overridep "Passed increase vote, t+4"
label variable f4overridel "Rejected increase vote, t+4"

#delimit;

esttab
	using "table A5.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
 		gap
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		stats(
			N
 			,
				label(
					"Observations"
				)
				fmt(%20.0fc)
		)
		mgroups(
			"Perot vote share 1992" "Nader vote share 1996"
			,
				pattern(1 0 0 1 0 0)
				prefix(\multicolumn{@span}{c}{) suffix(})
				span erepeat(\cmidrule(lr){@span})
		)			
		;
	
#delimit cr

*** control for lagged median income and lagged third party vote ***

*** covariates ***

local controls dfederalaidpcp dstateaidpcp lpopulation pct_white pct_senior pct_renter lmedianincome 
local economy davgannualwage demployment dunemployment propvaluechange

*** make interactions ***

foreach x in overridep overridel `economy' dfederalaidpcp dstateaidpcp {
	su `x'
	gen demincumbentX`x' = demincumbent*`x'
	replace `x' = demincumbentX`x'
}
label variable overridep "Tax increase*Dem incumbent"
label variable davg "Average wages*Dem incumbent"
label variable propvalue "Property values*Dem incumbent"
label variable dunemployment "Unemployment*Dem incumbent"
label variable demployment "Employment*Dem incumbent"
label variable dstateaidpcp "State aid*Dem incumbent"
label variable dfederal "Federal grants*Dem incumbent"

*** do the regressions ***

keep if !mi(demvoteshare) & !mi(demincumbentXoverridep)
tabulate year, gen(year_)

foreach x in `controls' `economy' {
	su `x'
	replace `x' = (`x' - `r(min)') / (`r(max)' - `r(min)')
}

gen l4othervoteshare = l4othervotes/l4totalvotes
drop othervotesh
gen othervotesh = othervotes/totalvotes*100

eststo clear

eststo: xi: reg demvoteshare lagdemvoteshare overridep year_* [aw=totalvotes], cl(town)
eststo: xi: reg demvoteshare lagdemvoteshare l4othervotesh l4lmedian overridep year_* [aw=totalvotes], cl(town)
esttab, se keep(*overridep*)
